package com.hph.demo;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

/**
 * 自定义编码器
 * @author 10499
 */
public class MessageEncoder extends MessageToByteEncoder<MessageDTO> {

    @Override
    protected void encode(ChannelHandlerContext ctx, MessageDTO msg, ByteBuf out) throws Exception {

        System.out.println("自定义编码器被调用");
        out.writeInt(msg.getLen());
        out.writeBytes(msg.getName());
    }
}
